package com.fbee.smartcommunities.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fbee.smartcommunities.entity.Repair;
import com.fbee.smartcommunities.entity.Visitor;
import com.fbee.smartcommunities.service.RepairService;
import com.fbee.smartcommunities.service.UploadFileService;
import com.fbee.smartcommunities.vo.ResultVO;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.minio.errors.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-21
 */
@RestController
@RequestMapping("/repair")
public class RepairController {

    @Resource
    private RepairService repairService;

    // 分页后内容
    @GetMapping("/list")
    public ResultVO<IPage<Repair>> getPage(Integer pageNo, Integer pageSize, String keyword , Boolean order , Boolean part) {
        return ResultVO.success(repairService.getPage(pageNo,pageSize,keyword,order,part));
    }

    @PostMapping("/changeState")
    public ResultVO<Boolean> changeState(Long id,Boolean state,String key){
        return ResultVO.success(repairService.changeState(id,state,key),"修改成功");
    }

    @GetMapping("/getById")
    public ResultVO<Repair> getById(Long id){
        return ResultVO.success(repairService.getById(id));
    }

    @PostMapping("/add")
    public ResultVO<Boolean> addRepair(String type,
                                       Long time,
                                       String content,
                                       String contact,
                                       String address,
                                       MultipartFile[] files,
                                       Long openId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        return ResultVO.success(repairService.addRepair(type,time,content,contact,address,files,openId),"提交成功");
    }

    @GetMapping("getByUid")
    public ResultVO<List<Repair>> getByUid(Long openId){
        return ResultVO.success(repairService.getListByUid(openId));
    }}
